<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>用户中心</title>
    <link rel="shortcut icon" href="../../favicon.ico">
    <!-- 引入样式 -->
    <!--    <link rel="stylesheet" href="../../plugins/element-ui/index.css" />-->
    <script src="../../js/vue.js"></script>
    <link rel="stylesheet" href="../../styles/common.css" />
    <link rel="stylesheet" href="../../styles/index.css" />
    <link rel="stylesheet" href="../../styles/icon/iconfont.css" />
    <link rel="stylesheet" href="../../element-ui/lib/theme-chalk/index.css">
    <script src="../../element-ui/lib/index.js"></script>


    <script src="../../js/axios-0.18.0.js"></script>



    <style>
        .body{
            min-width: 1366px;
        }
        .app-main{
            height: calc(100% - 64px);
        }
        .app-main .divTmp{
            width: 100%;
            height: 100%;
        }
        .hcqStyle6 {
            color: gold;
            letter-spacing: 0;
            text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135
        }
        .logo {
            text-align: center;
            background-color: rgb(52, 55, 68);
            padding: 46px 37px 67px 36px;
        }
    </style>
</head>

<body>
<div class="app" id="app">
    <div class="app-wrapper openSidebar clearfix">
        <!-- sidebar -->
        <div class="sidebar-container">
            <!--          <div class="logo">-->
            <!--            &lt;!&ndash; <img src="images/logo.png" width="122.5" alt="" /> &ndash;&gt;-->
            <!--            <img src="images/login/login-logo.png" alt="" style="width: 117px; height: 32px" />-->
            <!--          </div>-->
            <div class="logo">
                <el-image src="../../images/me.jpg/"></el-image>
            </div>



            <el-scrollbar wrap-class="scrollbar-wrapper">
                <el-menu
                        :default-active="defAct"
                        :unique-opened="false"
                        :collapse-transition="false"
                        background-color="#343744"
                        text-color="#bfcbd9"
                        active-text-color="#f4f4f5"
                >

                    <div v-for="item in menuList" :key="item.id">
                        <el-submenu :index="item.id" v-if="item.children && item.children.length>0">
                            <template slot="title">
                                <i class="iconfont" :class="item.icon"></i>
                                <span>{{item.name}}</span>
                            </template>
                            <el-menu-item
                                    v-for="sub in item.children"
                                    :index="sub.id"
                                    :key="sub.id"
                                    @click="menuHandle(sub,false)"
                            >
                                <i :class="iconfont" :class="sub.icon"></i>
                                <span slot="title">{{sub.name}}</span>
                            </el-menu-item
                            >
                        </el-submenu>
                        <el-menu-item v-else :index="item.id" @click="menuHandle(item,false)">
                            <i class="iconfont" :class="item.icon"></i>
                            <span slot="title">{{item.name}}</span>
                        </el-menu-item>
                    </div>
                </el-menu>
            </el-scrollbar>
        </div>
        <div class="main-container">
            <!-- <navbar /> -->
            <div class="navbar">
                <div class="head-lable">
              <span v-if="goBackFlag" class="goBack" @click="goBack()"
              ><img src="../../images/btn_back@2x.png" alt="" /> 返回</span
              >
                    <span>{{headTitle}}</span>

                </div>
                <el-button :plain="true" type="danger"

                           @click="logoutYes()"
                           style="float: right;margin-top: 10px;margin-right: 10px">退出登录</el-button>


            </div>
            <div class="app-main" v-loading="loading">
                <div class="divTmp" v-show="loading"></div>
                <iframe
                        id="cIframe"
                        class="c_iframe"
                        name="cIframe"
                        :src="iframeUrl"
                        width="80%"
                        height="auto"
                        frameborder="0"
                        v-show="!loading"
                ></iframe>
            </div>
        </div>
    </div>
</div>
<!--     开发环境版本，包含了有帮助的命令行警告-->
<script src="../../js/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<script>

    new Vue({
        el: '#app',
        data() {
            return {
                defAct: '1',
                menuActived: '1',
                userInfo: {},
                menuList: [
                    {
                        id: '1',
                        name: '图书查询',
                        url: 'book_search.html',
                        icon:'el-icon-setting'

                    },{
                        id: '2',
                        name: '借阅信息',
                        url: 'borrow_info.html',
                        icon:'el-icon-setting'

                    },
                    {
                        id: '3',
                        name: '借阅历史',
                        url: 'borrow_his.html',
                        icon:'el-icon-setting'

                    },
                    {
                        id: '4',
                        name: '个人信息设置',
                        url: 'edit_user_info.html',
                        icon:'el-icon-setting'
                    }

                ],
                iframeUrl: 'book_search.html',
                headTitle: '图书查询',
                goBackFlag: false,
                loading: true,
                timer: null
            }
        },
        computed: {},
        created() {
            // const userInfo = window.localStorage.getItem('userInfo')
            // if (userInfo) {
            //   this.userInfo = JSON.parse(userInfo)
            // }
            this.closeLoading()
        },
        beforeDestroy() {
            this.timer = null
            clearTimeout(this.timer)
        },
        mounted() {
            window.menuHandle = this.menuHandle
        },
        methods: {
            logoutYes() {
                this.$confirm('是否退出登录？', '警告', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/user/logout").then(res=>{
                        if (res.data.code === 1){
                            localStorage.removeItem('userInfo');
                            localStorage.removeItem('userInfoSimple')
                            top.location.replace("login.html");

                        }

                    })
                })
            },
            goBack() {
                // window.location.href = 'javascript:history.go(-1)'
                const menu = this.menuList.find(item=>item.id===this.menuActived)
                // this.goBackFlag = false
                // this.headTitle = menu.name
                this.menuHandle(menu,false)
            },
            menuHandle(item, goBackFlag) {
                this.loading = true
                this.menuActived = item.id
                this.iframeUrl = item.url
                this.headTitle = item.name
                this.goBackFlag = goBackFlag
                this.closeLoading()
            },
            closeLoading(){
                this.timer = null
                this.timer = setTimeout(()=>{
                    this.loading = false
                },1000)
            },
        }
    })
</script>
</body>
</html>
